package org.example.AQS;

import java.util.concurrent.locks.AbstractQueuedSynchronizer;

public class Sync extends AbstractQueuedSynchronizer {
        @Override
        protected int tryAcquireShared(int acquires) {
            // 尝试获取锁
            return (getState() == 0) ? 1 : -1;
        }

        @Override
        protected boolean tryReleaseShared(int releases) {
            // 释放锁
            setState(0);
            return true;
        }
    }